#!/bin/bash

# 设置要使用的端口
PORT=9090

# 检查是否有Java进程正在运行，并杀死它
if pgrep -f "file-share-1.0-SNAPSHOT.jar" >/dev/null; then
    echo "Stopping existing file-share application..."
    pkill -f "file-share-1.0-SNAPSHOT.jar"
    sleep 5 # 等待一段时间确保进程完全关闭
fi

# 启动新的Spring Boot应用程序
nohup java -Xmx512m -jar file-share-1.0-SNAPSHOT.jar --server.port=$PORT --file.max-size=1GB --file.location=/opt/project/file-share >/dev/null 2>&1 &


# 开启防火墙端口
firewall-cmd --zone=public --add-port=$PORT/tcp --permanent
firewall-cmd --reload

# systemctl start firewalld

echo "Application started on port $PORT."